package org.alex.samples.util;

import java.math.BigInteger;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;

public class MD5Util {

	public static String toMD5(String password) {
		String strMD5 = "";
		try {
			MessageDigest md = MessageDigest.getInstance("MD5");
			strMD5 = new BigInteger(1, md.digest(password.getBytes())).toString(16);
			String temp = "";
			for (int i = 0; i < 32 - strMD5.length(); i++) {
				temp += '0';
			}
			strMD5 = new StringBuilder(strMD5).insert(0, temp).toString();
		} catch (NoSuchAlgorithmException e) {
			e.printStackTrace();
		}
		return strMD5;
	}

}
